package acm.BigData;

import java.util.*;

/**
 * Created by Administrator on 2017/7/11.
 * 这个测试是：一百个人每人一百块，每次某个人给某个人1块，最终是什么样
 */
public class HundredPHM {

    static List<Person> people = new ArrayList<>();
    static Integer times = 0;

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            people.add(new Person(i, 250));
        }
        for (int i = 0; i < 10000000; i++) {
            Random random = new Random();
            Integer provider = random.nextInt(100);
            Integer receivder = random.nextInt(100);
            giveMoney(provider, receivder);
        }
        Collections.sort(people);
        System.out.println(times + "--------------------");
        for (Person person : people) {
            System.out.println(person.toString());
        }
    }

    private static void giveMoney(Integer provider, Integer receivder) {
        if (provider == receivder) {
            times ++ ;
//            System.out.println("amazing! " + provider);
        }
        people.get(provider).outMoney();
        people.get(receivder).addMoney();
    }

}

class Person implements Comparable<Person>{

    Integer id;
    Integer money;

    public Person(Integer id) {
        this.id = id;
        this.money = 100;
    }

    public Person(Integer id, Integer money) {
        this.id = id;
        this.money = money;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id=" + id +
                ", money=" + money +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getMoney() {
        return money;
    }

    public void setMoney(Integer money) {
        this.money = money;
    }

    public void addMoney() {
        this.money += 1;
    }
    public void outMoney() {
        this.money -= 1;
    }


    @Override
    public int compareTo(Person o) {
        return this.getMoney() - o.getMoney();
    }

}
